<template>

  <div id="addShipping" class="addShipping">
    <!-- header -->
    <yd-navbar slot="navbar" fixed>
      <a @click="$router.go(-1)" slot="left">
        <yd-navbar-back-icon></yd-navbar-back-icon>
      </a>
      <span slot="center" style="font-size:18px">添加地址</span>
    </yd-navbar>
    <!-- content -->
    <div class="content-addShipping" fixed>
      <yd-cell-item>
        <span slot="left">收件人：</span>
        <yd-input slot="right" v-model="item.receiverName" placeholder="请输入收件人姓名"></yd-input>
      </yd-cell-item>
      <yd-cell-item>
        <span slot="left">联系电话：</span>
        <yd-input slot="right" v-model="item.receiverPhone" placeholder="请输入电话号码" ref="mobile" regex="mobile" :showSuccessIcon="false"></yd-input>
      </yd-cell-item>
      <yd-cell-item>
        <span slot="left">手机号：</span>
        <yd-input slot="right" v-model="item.receiverMobile" placeholder="请输入手机号" ref="mobile" regex="mobile" :showSuccessIcon="false"></yd-input>
      </yd-cell-item>
      <yd-cell-item>
        <span slot="left">选择省份：</span>
        <yd-input slot="right" v-model="item.receiverProvince" placeholder="请选择省份"></yd-input>
      </yd-cell-item>
      <yd-cell-item>
        <span slot="left">收货地址：</span>
        <yd-input slot="right" v-model="item.receiverAddress" placeholder="请选择收货姓名"></yd-input>
      </yd-cell-item>
      <yd-cell-item>
        <span slot="left">邮编：</span>
        <yd-input slot="right" v-model="item.receiverZip" placeholder="请选择收货姓名"></yd-input>
      </yd-cell-item>
      <yd-button size="large" @click.native="add()" bgcolor="#2196f3" color="#fff">添加</yd-button>

    </div>

  </div>

</template>

<script>
  import baseService from '../../axios/'
  export default {
    name: 'addShipping',
    data() {
      return {
        message: '添加地址',
        item: {
          receiverName: '',
          receiverPhone: '',
          receiverMobile: '',
          receiverProvince: '',
          receiverAddress: '',
          receiverZip: ''
        }
      }
    },
    methods: {
      add() {
        let param = new URLSearchParams();
        let receiverName = this.item.receiverName;
        let receiverPhone = this.item.receiverPhone;
        let receiverMobile = this.item.receiverMobile;
        let receiverProvince = this.item.receiverProvince;
        let receiverAddress = this.item.receiverAddress;
        let receiverZip = this.item.receiverZip;
        param.append("receiverName", receiverName);
        param.append("receiverPhone", receiverPhone);
        param.append("receiverMobile", receiverMobile);
        param.append("receiverProvince", receiverProvince);
        param.append("receiverAddress", receiverAddress);
        param.append("receiverZip", receiverZip);
        baseService.post('shipping/add.do', param).then((res) => {
          if (res.data.status == 0) {
            this.$dialog.alert({
              mes: res.data.msg
            });
            this.$router.push({
              path: '/user/shipping'
            })
          }
        })
      }
    }
  }

</script>

<style>
  .addShipping .content-addShipping {
    position: fixed;
    padding-top: 15%;
    height: 94%;
    width: 100%;
    overflow-y: auto !important;
  }

  .content-addShipping .yd-cell-item {
    border-bottom: solid !important;
    border-bottom-color: #f2f2f2 !important;
  }

</style>
